package com.qdu.hyy.DirectorAverageRating;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

public class DirectorAverageRatingDriver {

    public static void main(String[] args) throws Exception {

//        if (args.length != 2) {
//            System.err.println("Usage: DirectorAverageRatingDriver <input path> <output path>");
//            System.exit(-1);
//        }

        Configuration conf = new Configuration();

        Job job = Job.getInstance(conf, "Director Average Rating");
        job.setJarByClass(DirectorAverageRatingDriver.class);

        job.setMapperClass(DirectorAverageRatingMapper.class);
        job.setMapOutputKeyClass(Text.class);
        job.setOutputValueClass(DoubleWritable.class);
        job.setCombinerClass(DirectorAverageRatingReducer.class); // 可选，用于优化Mapper和Reducer之间的数据传输
        job.setReducerClass(DirectorAverageRatingReducer.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(DoubleWritable.class);


        FileInputFormat.addInputPath(job, new Path("input/hyy/movies_complete.csv"));
        FileOutputFormat.setOutputPath(job, new Path("output/job3"));

        System.exit(job.waitForCompletion(true) ? 0 : 1);
    }
}